package com.team.dao;

import java.util.List;
import java.sql.SQLException;
import java.sql.ResultSet;
import com.team.entity.Project;
import com.team.util.DbHelp;
import com.team.util.ResultSetPackge;

public class ProjDao {
	DbHelp<Project> db = new DbHelp<Project>();
	

	
	public int saveProj(Project project){
		String sql = "insert into t_project(projname,content,createtime,endtime)values(?,?,?,?)";
		return db.executeUpdateSql(sql, project.getProjName(),project.getContent(),project.getCreateTime(),project.getEndTime());
	}
	public Project selectProjId(Project proj){
		String sql = "select id,projname,content,createtime,endtime from t_project where projname=? and createtime=? and endtime=?";
		return db.exeSelectForObject(sql, new PackgeProject(), proj.getProjName(),proj.getCreateTime(),proj.getEndTime());
	}
	public List<Project> selectAllProject(){
		String sql = "select id,projname,content,createtime,endtime from t_project";
		return db.exeSelectForList(sql, new PackgeProject());
	}
	private class PackgeProject implements ResultSetPackge<Project>{

		public Project packgeResultSet(ResultSet rs) throws SQLException {
			Project proj = new Project();
			proj.setId(rs.getInt("id"));
			proj.setCreateTime(rs.getString("createtime"));
			proj.setContent(rs.getString("content"));
			proj.setProjName(rs.getString("projname"));
			proj.setEndTime(rs.getString("endtime"));
			return proj;
		}
		
		
	}
	
	public Project selectById(int id) {
		String sql = "select id,projname,content,createtime,endtime from t_project where id = ?";
		return db.exeSelectForObject(sql, new PackgeProject(), id);
	}
	public int updateProj(Project project) {
		String sql = "update t_project set projname = ?,content = ?,createtime = ?,endtime = ? where id = ?";
		return db.executeUpdateSql(sql, project.getProjName(),project.getContent(),project.getCreateTime(),project.getEndTime(),project.getId());
	}

	
}
